<title>房间详情 - {:getSettingOptionsCache('base.web_site_title') ?: '后台管理系统模板'}</title>
<!--表格插件css-->
<link rel="stylesheet" href="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" type="text/css" href="{:HTTP_STATIC_ADMIN_CDN_URL}css/style.min.css">
<!--时间日期选择器css-->
<link rel="stylesheet" type="text/css" href="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <header class="card-header">
                    <div class="card-title">{$roomInfo.room_id}-房间详情</div>
                </header>
                <div class="card-body">

                    <form id="searchForm" class="row row-cols-lg-auto g-3 align-items-center">
                        <div class="col-12 mb-1">
                            <div class="input-group">
                                <div class="input-group-prepend search-bar">
                                    <input type="hidden" name="uid_keyword_field" class="search-field" value="white_uid">
                                    <button class="btn search-btn btn-default dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">白棋玩家id</button>
                                    <div class="dropdown-menu">
                                        <a class="dropdown-item" href="javascript:void(0)" data-field="white_uid">白棋玩家id</a>
                                        <a class="dropdown-item" href="javascript:void(0)" data-field="black_uid">黑棋玩家id</a>
                                    </div>
                                </div>
                                <input type="text" class="form-control" autocomplete="off" value="" id="uid_keyword_value" name="uid_keyword_value" placeholder="请输入关键词">
                            </div>
                        </div>
                        <div class="col-12 mb-1">
                            <div class="input-group d-flex">
                                <span class="btn btn-default disabled-button-pointer">棋局时间</span>
                                <input class="form-control" type="text" data-provide="datetimepicker" name="datetime" placeholder="请选择具体时间" value="" data-side-by-side="true" data-format="YYYY-MM-DD HH:mm:ss" />
                                <span class="input-group-text">~</span>
                                <input class="form-control" type="text" data-provide="datetimepicker" name="datetime" placeholder="请选择具体时间" value="" data-side-by-side="true" data-format="YYYY-MM-DD HH:mm:ss" />
                            </div>
                        </div>
                        <div class="col-12 mb-1 d-flex lyear-select-mg-0">
                            <span class="btn btn-default disabled-button-pointer">棋局结果</span>
                            <select name="state" class="exampleSelect" data-width="200px">
                                <option value="">全部</option>
                                <option value="1">开启</option>
                                <option value="2">关闭</option>
                            </select>
                        </div>
                        <div class="col-12 mb-1">
                            <button type="submit" class="btn btn-default me-1 sreach-all"><i class="mdi mdi-magnify"></i> 搜索</button>
                        </div>
                    </form>

                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/layer/src/layer.js"></script>
<!--加载插件-->
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/lyear-loading.js"></script>
<!--表格插件js-->
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.js"></script>
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--日期选择插件-->
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/momentjs/moment.min.js"></script>
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/momentjs/locale/zh-cn.min.js"></script>
<!--socket-->
<script src="{:HTTP_STATIC_ADMIN_LOCAL_URL}js/common/md5.js"></script>
<script src="{:HTTP_STATIC_ADMIN_LOCAL_URL}js/common/socket/lib/message.js"></script>
<script src="{:HTTP_STATIC_ADMIN_LOCAL_URL}js/common/socket/socket.js"></script>

<script>
    socketConnect("{:WEBSOCKET_IP}", "{:WEBSOCKET_PORT}", "{:WEBSOCKET_PRIVATE_KEY}")
    let objHtml = [
        {
            'title': '棋局详情',
            'a-class': 'edit-btn',
            'icon': 'mdi-view-list',
            'event': (event, value, row, index) => {
                openPage({
                    url: "{:url('/admin/match')}",
                    param: {
                        room_id: '{$roomInfo.room_id}',
                        match_id: row.match_id
                    }
                }, '棋局列表');
            }
        },
        {
            'title': '结束棋局',
            'a-class': 'close-btn',
            'icon': 'mdi-window-close',
            'event': (event, value, row, index) => {
                if (row.outcome !== 0) {
                    showInfoNotify('棋局已结束');
                    return;
                }
                if(socket.socket.readyState !== WebSocket.OPEN){
                    showWarningNotify('Socket未连接');
                    return;
                }
                reconfirm({
                    url: "{:url('/admin/room/end')}",
                    param: {id: row.id},
                    success: (res) => {
                        if(res.code === 200){
                            refreshTable();
                            showInfoNotify('正在发送Socket信息...')
                            socketSend('systemEndGame', {
                                room_id: '{$roomInfo.room_id}',
                            }, (loader = $('body').lyearloading({
                                opacity: 0.2,
                                spinnerSize: 'lg'
                            })) => {loader.destroy();});
                        }
                    }
                }, '确定结束棋局吗', '请再次确认是否结束棋局？');
            }
        },
    ];
    let outcome = {
        1: {
            name: '白棋胜',
            color: 'bg-light text-dark shadow-sm'
        },
        2: {
            name: '黑棋胜',
            color: 'bg-dark',
        },
        3: {
            name: '平局',
            color: 'bg-primary',
        },
        1006: {
            name: '系统级-平局',
            color: 'bg-primary',
        },
    };
    const requestUrl = "{:url('/admin/room/dlist',['id' => $roomInfo['id']])}";
    const columns = [{
        field: 'white_username',
        title: '白棋玩家',
        align: 'center',
        width: 8,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'black_username',
        title: '黑棋玩家',
        align: 'center',
        width: 8,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'outcome',
        title: '棋局结果',
        align: 'center',
        width: 6,
        // 宽度单位
        widthUnit: 'rem',
        formatter: (value, row, index) => {
            return outcome[value] ? `<span class="badge ${outcome[value].color}">${outcome[value].name}</span>` : '-';
        }
    }, {
        field: 'starttime',
        title: '开始时间',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter: (value, row, index) => {
            return makeData(value);
        }
    }, {
        field: 'endtime',
        title: '结束时间',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter: (value, row, index) => {
            return makeData(value);
        }
    }, {
        field: 'operate',
        title: '操作',
        align: 'center',
        width: 6,
        // 宽度单位
        widthUnit: 'rem',
        formatter: btnGroup(objHtml),  // 自定义方法
        events: btnEvents(objHtml)
    }];
</script>
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_LOCAL_URL}js/common/table.js"></script>
<script>
    $(function () {
        $('.sreach-all').click(function () {
            refreshTable();
        });

        $('#searchForm').submit(function(){
            event.preventDefault();
        });
    });

    //下拉框更新样式
    $('.exampleSelect').each(function() {
        var $this = $(this);
        $this.lyearSelect({
            width: $this.data('width') ? $this.data('width') : '', // width示例：75px、50%
            placeholder: $this.data('placeholder') ? $this.data('placeholder') : '请选择',
            search: $this.data('search') ? $this.data('search') : false,
        });
    });

    //下拉选择搜索项
    $('.search-bar .dropdown-menu a').click(function() {
        $(this).parents('.search-bar').find('.search-field').val(($(this).data('field') || ''));
        $(this).parents('.search-bar').find('.search-btn').html($(this).text());
    });
</script>